<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    
  </style>
</head>
<body>

  <textarea id="txt1"></textarea>
  <input type="button" value="发送" id="btn">
  <textarea id="txt2" disabled></textarea>
  
</body>
<script>

  var txt1 = document.querySelector("#txt1");
  var txt2 = document.querySelector("#txt2");
  var btn = document.querySelector("#btn");

  var arr = ["abc", "123", "你好", "!"];

  btn.onclick = function(){
    var str = txt1.value

    // 遍历敏感词库，拼接将来创建正则所需的字符内容
    var regStr = "";
    for(var i=0;i<arr.length;i++){
      regStr += "("+ arr[i] +")|";
    }
    // 通过拼接完成后的正则字符，创建正则
    var reg = new RegExp("("+ regStr.slice(0,-1) +")+", "g");
    
    txt2.value = str.replace(reg, "*");
  }
  
</script>
</html>